
module.exports = function ($scope, $state, $stateParams,$resource,$modal,items,$modalInstance) {  
                $scope.str2date = function(strDate){

			if(angular.isString(strDate))
			{
				var objDate = new Date(Date.parse(strDate.replace(/-/g, "/")));

				return objDate;
			}
			else
			{
				return '错误格式';
			}
			
		}

        $scope.date2str = function (objDate){

			if(angular.isDate(objDate))
			{
				var y = objDate.getFullYear();
				var m = objDate.getMonth();
				var d = objDate.getDate();

				return y + '-' + (m + 1) + '-' + d;
			}
			else
			{
				return '错误格式';
			}
		}
console.log(items);
$scope.obj = items;
$scope.obj.start_time = $scope.str2date($scope.obj.start_time);
$scope.obj.start_time = $scope.date2str($scope.obj.start_time);
$scope.obj.end_time = $scope.str2date($scope.obj.end_time);
$scope.obj.end_time = $scope.date2str($scope.obj.end_time);
$scope.a={};
$scope.employee='';
$scope.a.ctarr=[
    {name:'普通货车',value:'0'},
    {name:'厢式专用运输车',value:'1'},
    {name:'灌式专用运输车',value:'2'},
]
$scope.a.dtarr=[
    {name:'爆炸品',value:'0'},
    {name:'压缩气体',value:'1'},
    {name:'易燃液体',value:'2'},
    {name:'易燃固体',value:'3'},
    {name:'氧化物有机过氧化物',value:'4'},
    {name:'有毒物质',value:'5'},
    {name:'放射性物质',value:'6'},
    {name:'腐蚀品',value:'7'},
    {name:'其他危险品（电池组）',value:'8'},
]


$scope.submit = function(){
    if(!angular.isString($scope.obj.start_time)){
        $scope.obj.start_time = $scope.date2str($scope.obj.start_time);
    }
    if(!angular.isString($scope.obj.end_time)){
        $scope.obj.end_time = $scope.date2str($scope.obj.end_time);
    }
    
    var para = {
        order_code:$scope.obj.order_code,
        start_place:$scope.obj.start_place,
        end_place:$scope.obj.end_place,
        start_time:$scope.obj.start_time,
        end_time:$scope.obj.end_time,
        estimated_distance:$scope.obj.estimated_distance,
        estimated_price:$scope.obj.estimated_price,
        car_type:$scope.obj.car_type,
        danger_type:$scope.obj.danger_type,
        goods_name:$scope.obj.goods_name,
        goods_weight:$scope.obj.goods_weight,
        contact_name:$scope.obj.contact_name,
        contact_mobile:$scope.obj.contact_mobile
     }

     console.log(para);
     $resource('/api/ac/dsc/supplyService/create', {}, {}).save(para, function(res){
            if(res.errcode === 0){            
                 alert('操作成功');
                 $modalInstance.close();
            }else{
                alert(res.errmsg);
           
            }
        });
}

            //正则判断电话号  
            $scope.checkphone=function(x){
                if(!/^1[34578]\d{9}$/.test(x)) return "您输入的电话号长度或格式错误";
            }
			$scope.showphoneinfo=function(x){
                console.log(x);
                if(x==undefined){
                    $scope.employee.phoneinfo="";
                   return;
                  }
                if(x==''){
                    $scope.employee.phoneinfo="";
                   return;
                  }
                                         
            if($scope.checkphone(x)=="您输入的电话号长度或格式错误"){                
                $scope.employee.phoneinfo="您输入的电话号长度或格式错误"
            }else{
                     $scope.employee.phoneinfo="";
                    }
            }


            	$scope.start = {
                        'date' : '',
                        'opened' : false,
                    };

                    $scope.end = {
                        'date' : '',
                        'opened' : false,
                    };

                    $scope.open = function(obj) {
                        obj.opened = true;
                    }




};
